<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <!-- basic styles -->
        <link href="../assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="../assets/css/font-awesome.min.css" />
        <link rel="stylesheet" href="../assets/css/ace.min.css" />
        <link rel="stylesheet" href="../assets/css/ace-rtl.min.css" />
        <link rel="stylesheet" href="../assets/css/ace-skins.min.css" />
        <link rel="stylesheet" type="text/css" media="all" href="../assets/js/date-time/daterangepicker-bs3.css"/>
        <style>
            .search_bar{
                padding-bottom: 5px;
                width:100%;
                margin: 0px;
            }
            .search_bar div{
                float: left;
                margin-left: 10px;
                margin-top: 5px;
            }
            .search_bar div strong{
                font-weight: lighter;
                padding-right: 3px;
            }
            .search_bar div input{
                width:160px;
            }
            .search_bar div select{
                width:160px;
            }
            .search{
                border-width:4px;
            }
            .centen{text-align: center}
            .dialog_textarea{
                width: 98%;
                height:150px;
                padding: 1%;
            }

        </style>
    </head>
    <body>
        <div class="main-container">
            <div class="col-xs-12">
                <h3 class="header smaller lighter blue">策略接收日志</h3>
                <div class="row search_bar">
                    <!--起始时间:-->
                    <div>
                        <strong>起始时间:</strong>
                        <input type="text" id="startTime" />
                    </div>
                    <!--结束时间:-->
                    <div>
                        <strong>结束时间:</strong>
                        <input type="text" id="endTime" />
                    </div>
                    <!--策略类型:-->
                    <div>
                        <strong>策略类型:</strong>
                        <select id="MessageType">
                            <option value="">全选</option>
                        </select>
                    </div>
                    <!--策略仓库:-->
                    <div>
                        <strong>策略仓库:</strong>
                        <select id="policyDepot">
                            <option value="">全选</option>
                        </select>
                    </div>
                    <!--策略名称:-->
                    <div>
                        <strong>策略名称:</strong>
                        <select id="MessageNo">
                            <option value="">全选</option>
                        </select>
                    </div>
                    <!--设备名称:-->
                    <div>
                        <strong>设备名称:</strong>
                        <select id="device_id"></select>
                    </div>
                    <div>
                        <button class="btn btn-success btn-xs search" onclick="search()">查&nbsp;询</button>
                    </div>
                </div>
                <div class="table-header">
                    日志查看
                </div>
                <div class="table-responsive">
                    <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>id</th>
                                <th>设备名称</th>
                                <th>策略类型</th>
                                <th>策略编号</th>
                                <th>策略序列号</th>
                                <th>策略发送IP地址</th>
                                <th>策略上报时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <script src="../assets/js/jquery.js"></script>
        <script src="../assets/js/bootstrap.min.js"></script>
        <!-- page specific plugin scripts -->
        <script src="../assets/js/jquery-ui-1.10.3.custom.min.js"></script>
        <script src="../assets/js/jquery.dataTables.min.js"></script>
        <script src="../assets/js/jquery.dataTables.bootstrap.js"></script>
        <script src="../assets/js/date-time/moment.js"></script>
        <script src="../assets/js/date-time/daterangepicker.js"></script>
        <script src="../assets/js/Base64.js"></script>
        <script type="text/javascript">
                            var base64 = new Base64();
                            var oTable1;
                            function showTable(url) {
                                var oper = '';
                                oper += "<a class='blue' href='javascript:void(0)' title='查看' '>";
                                oper += "    <i class='icon-pencil bigger-130'></i>";
                                oper += "</a>";


                                if (oTable1) {
                                    oTable1.fnDestroy();
                                }
                                oTable1 = $('#sample-table-2').dataTable({
                                    "aoColumns": [
                                        {"bSortable": false, "sWidth": "50px", "sClass": "centen"},
                                        {"bSortable": false, "sWidth": "140px", "sClass": "centen"},
                                        {"bSortable": false, "sWidth": "80px", "sClass": "centen"},
                                        {"bSortable": false, "sWidth": "80px", "sClass": "centen"},
                                        {"bSortable": false, "sWidth": "90px", "sClass": "centen"},
                                        {"bSortable": false, "sWidth": "140px", "sClass": "centen"},
                                        {"bSortable": false, "sWidth": "140px", "sClass": "centen"},
                                        {"bSortable": false, "sWidth": "140px", "sClass": "centen", "sDefaultContent": oper}
                                    ],
                                    "bFilter": false,
                                    "bSort": false,
                                    "bProcessing": true,
                                    "bServerSide": true,
                                    "sAjaxSource": url,
                                    "sAjaxDataProp": "aaData"
                                });
                                $('#sample-table-2').css("width", "100%");

                                $(".table tbody").on('click', 'a', function () {
                                    var id = $(this).parents("tr").find("td").first().html();
                                    $.post("../action/message/util/messageincominglogview.do", {logId: id}, function (data) {
                                        openDialog(data);
                                    }, "json");

                                });
                            }
                            ;
                            //时间格式转换为时间戳
                            function js_strto_time(time) {
                                var new_str = time.replace(/:/g, '-');
                                new_str = new_str.replace(/ /g, '-');
                                new_str = new_str.replace(/\//g, '-');
                                var arr = new_str.split("-");
                                var datum = new Date(Date.UTC(arr[0], arr[1] - 1, arr[2], arr[3] - 8, arr[4], arr[5]));
                                return strtotime = datum.getTime() / 1000;
                            }
                            //转换为正常时间格式
                            function tr_time(str) {
                                str = str.split(" ");
                                var yymmdd = str[0];
                                var hh = str[1].split(":")[0];
                                var mi = str[1].split(":")[1];
                                var astr = str[2];
                                if (astr == "PM") {
                                    hh = 12 + parseInt(hh);
                                }
                                return yymmdd + " " + hh + ":" + mi + ":00";
                            }
                            //时间戳数据转换为时间格式
                            function js_date_time(unixtime) {
                                var timestr = new Date(parseInt(unixtime) * 1000);
                                var datetime = timestr.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
                                if (datetime.indexOf("上午") != -1) {
                                    datetime = datetime.replace(/上午/g, "");
                                    datetime = datetime.split(":")[0] + ":" + datetime.split(":")[1];
                                    datetime = datetime + " AM"
                                }
                                if (datetime.indexOf("下午") != -1) {
                                    datetime = datetime.replace(/下午/g, "");
                                    datetime = datetime.split(":")[0] + ":" + datetime.split(":")[1];
                                    datetime = datetime + " PM"
                                }
                                return datetime;
                            }
                            //填充策略类型
                            function getPolicyLibrary() {
                                var data = {
                                    "0xC1": "DPI模块心跳信息",
                                    "0xC2": "DPI模块策略同步请求",
                                    "0xC5": "DPI设备状态查询回应(静态信息)",
                                    "0xC6": "DPI设备状态查询回应(动态信息)",
                                    "0x03": "URL 分类批量查询",
                                    "0x83": "AAA信息反查"
                                };
                                $("#MessageType").html("");
                                $("#MessageType").append("<option value=''>全选</option>");
                                for (var i in data) {
                                    $("#MessageType").append("<option value='" + i + "'>" + data[i] + "</option>")
                                }
                            }
                            ;
                            function getPolicyDepot(type) {
                                $.ajax({
                                    type: "GET",
                                    async: false,
                                    url: "../policy/get_strategy_all_warehouse",
                                    data: {MessageType: type},
                                    dataType: "json",
                                    success: function (data) {
                                        $("#policyDepot").html("");
                                        $("#policyDepot").append("<option value=''>全选</option>")
                                        for (var i in data) {
                                            $("#policyDepot").append("<option value='" + type + "'>" + data[i].policy_warehouse_name + "</option>")
                                        }
                                    }
                                });
                            }
                            ;
                            function getPolicyAll(type, instance) {
                                var obj;
                                $.ajax({
                                    type: "GET",
                                    async: false,
                                    url: "../action/policy/list.do",
                                    data: {type: type, instance: base64.encode(instance)},
                                    dataType: "json",
                                    success: function (data) {
                                        $("#MessageNo").html("");
                                        $("#MessageNo").append("<option value=''>全选</option>");
                                        for (var i in data) {
                                            $("#MessageNo").append("<option value='" + data[i].MessageNo + "'>" + data[i].Description + "</option>")
                                        }
                                    }
                                });
                                return obj;
                            }
                            //获取所有设备
                            function getDeviceAll() {
                                $.ajax({
                                    type: "GET",
                                    async: false,
                                    url: "../action/device/list.do",
                                    data: {type:"all"},
                                    dataType: "json",
                                    success: function (data) {
                                        $("#device_id").html("");
//                                        $("#device_id").append("<option value=''>全选</option>");
                                        for (var i in data) {
                                            $("#device_id").append("<option value='" + data[i].id + "' title='" + data[i].ip + "'>" + data[i].name + "</option>")
                                        }
                                    }
                                });
                            }
                            function search() {
                                var obj = {};
                                obj.id = $("#device_id").val();
                                obj.ip = $("#device_id").find("option:selected").attr("title");
                                if (obj.id == "") {
                                    obj.id = "";
                                    obj.ip = "";
                                }
                                obj.startTime = tr_time($("#startTime").val());
                                obj.startTime = js_strto_time(obj.startTime);
                                obj.endTime = tr_time($("#endTime").val());
                                obj.endTime = js_strto_time(obj.endTime);
                                obj.MessageType = $("#MessageType").val();
                                obj.MessageNo = $("#MessageNo").val();
                                if (obj.MessageType == "") {
                                    obj.MessageType = "";
                                    obj.MessageNo = "";
                                }

                                var url = "../action/log/query_policy_receive_log.do?id=";
                                url += obj.id + "&ip=";
                                url += obj.ip + "&startTime=";
                                url += obj.startTime + "&endTime=";
                                url += obj.endTime + "&MessageType=";
                                url += obj.MessageType + "&MessageNo=";
                                url += obj.MessageNo;
                                showTable(url);
                            }
                            jQuery(function ($) {

                                $("#MessageType").change(function () {
                                    var type = $(this).val();
                                    //填充策略库
                                    getPolicyDepot(type);
                                })
                                $("#policyDepot").change(function () {
                                    var type = $(this).val();
                                    var instanceName = $(this).find("option:selected").text();
                                    //填充策略
                                    getPolicyAll(type, instanceName);
                                })
                                //时间插件
                                var date = new Date();
                                var time = date.getTime() + "";
                                time = time.substr(0, 10);
                                time = parseInt(time);
                                $('#startTime').val(js_date_time(time));
                                $('#endTime').val(js_date_time(time));
                                $('#startTime').daterangepicker({
                                    timePicker: true,
                                    singleDatePicker: true,
                                    timePickerIncrement: 1,
                                    format: 'YYYY/MM/DD h:mm A'
                                });
                                $('#endTime').daterangepicker({
                                    timePicker: true,
                                    singleDatePicker: true,
                                    timePickerIncrement: 1,
                                    format: 'YYYY/MM/DD h:mm A'
                                });
                                getPolicyLibrary();
                                getDeviceAll();
                                setInterval(function () {
                                    parent.$("#page-content").attr("height", $("html").height());
                                }, 500);
                            });





                            //添加查看策略弹窗
                            function openDialog(data) {
                                closeDialog();
                                var cont = '';
                                cont += "<div id='modal-wizard' class='modal'>";
                                cont += "            <div class='modal-dialog'>";
                                cont += "                <div class='modal-content'>";
                                cont += "                    <div class='modal-header' data-target='#modal-step-contents'>";
                                cont += "                        <h3>查看策略内容</h3>";
                                cont += "                    </div>";
                                cont += "                    <div class='modal-body step-content' id='modal-step-contents'>";
                                cont += "                        <div class='' id='modal-step1'>";
                                cont += "                            <div class='center'>";
                                cont += "                                <form class='form-horizontal'>";
                                cont += "                                    <div class='form-group'>";
                                //cont += "                                        <label for='Dev_Name' class='col-sm-3 control-label no-padding-right'>查看策略内容</label>";
                                cont += "                                            <textarea class='dialog_textarea' readonly>" + data.bin + "</textarea>";
                                cont += "                                            <textarea class='dialog_textarea' readonly>" + base64.decode(data.json) + "</textarea>";
                                cont += "                                    </div>";
                                cont += "                                </form>";
                                cont += "                            </div>";
                                cont += "                        </div>";
                                cont += "                    </div>";
                                // cont += "                    <div class='modal-footer wizard-actions'>";
                                // cont += "                        <button class='btn btn-success btn-sm btn-next save' data-last='完成 ' onclick='saveGroup()'>";
                                // cont += "                            完成";
                                // cont += "                            <i class='icon-ok'></i>";
                                // cont += "                        </button>";
                                // cont += "                        <button class='btn btn-danger btn-sm pull-left' data-dismiss='modal'>";
                                // cont += "                            <i class='icon-remove'></i>";
                                // cont += "                            取消";
                                // cont += "                        </button>";
                                // cont += "                    </div>";
                                cont += "                </div>";
                                cont += "            </div>";
                                cont += "        </div>";
                                $("body").append(cont);

                                $('#modal-wizard').modal("show");
                            }

                            //关闭用户组弹窗
                            function closeDialog() {
                                $('#modal-wizard').modal("hide");
                                $('#modal-wizard').remove();
                            }

        </script>
    </body>
</html>
